package com.kerrykidz.system.util.sync;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.kerrykidz.common.PrimaryKeyGenerator;

/**
 * 
 * @Desc 一个同步批次
 * @author QUINN
 * @date 2014年9月18日下午6:18:56
 */
public class MessageTask implements Serializable {

	public MessageTask() {
		this.taskId = PrimaryKeyGenerator.getRandomPrimaryKey();
	}

	public MessageTask(List<TableSyncMessage> messages) {
		this.messages = messages;
		this.taskId = PrimaryKeyGenerator.getRandomPrimaryKey();
	}

	private static final long serialVersionUID = 1L;
	private List<TableSyncMessage> messages;
	private String taskId;

	public List<TableSyncMessage> getMessages() {
		return messages;
	}

	public void setMessages(List<TableSyncMessage> messages) {
		this.messages = messages;
	}

	public String getTaskId() {
		return taskId;
	}

	/**
	 * 
	 * @Desc
	 * @author QUINN
	 * @date 2014年9月18日下午6:18:38
	 * @param list
	 * @param sync
	 * @return
	 */
	public static List<SyncMessage> format(List<Map<String, Object>> list, SyncBean sync) {

		List<SyncMessage> messages = new ArrayList<SyncMessage>();

		for (Map<String, Object> map : list) {
			SyncMessage message = new DataMessage(sync, (String) map.get(sync.getPrimary()), map);
			messages.add(message);
		}
		return messages;
	}

}
